package com.xyz.entity.response;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xyz.enums.ResponseEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.Collection;

/**
 * @author 夏永泽
 * @date 2022/3/29
 */
@Data
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class ResultResponsePage<T> {
    private String code;
    private String message;
    private Collection<T> data;
    private Long total;

    public static <T> ResultResponsePage<T> success(Page<T> page) {
        return new ResultResponsePage<>(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMessage(), page.getRecords(), page.getTotal());
    }

    public static <T> ResultResponsePage<T> success(String message, Page<T> page) {
        return new ResultResponsePage<>(ResponseEnum.SUCCESS.getCode(), message, page.getRecords(), page.getTotal());
    }
}
